package collection.Demo05;

import collection.Demo02.Student;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @Author Miku
 * @Create 2021/4/13 14:47
 * ArrayList的使用
 */
public class Test {
    public static void main(String[] args) {
        //创建集合
        ArrayList arrayList = new ArrayList();
        Student s1 = new Student("miku",16);
        Student s2 = new Student("yae_sakura",18);
        Student s3 = new Student("test",20);
        //添加元素
        arrayList.add(s1);
        arrayList.add(s2);
        arrayList.add(s3);
        System.out.println("元素个数:"+arrayList.size());
        System.out.println(arrayList);
        //删除元素
        arrayList.remove(s1);
        System.out.println("删除后元素个数:"+arrayList.size());
        System.out.println(arrayList);
        //遍历元素
        for (Object o : arrayList) {
            System.out.println(o);
        }
    }
}
